iT邦幫忙

2021 iThome 鐵人賽

DAY 14
0

自己寫看看轉場-0.0從空白開始

從res右鍵選transition

https://ithelp.ithome.com.tw/upload/images/20220202/20119035B7V8QGTBEl.png

https://ithelp.ithome.com.tw/upload/images/20220202/20119035AphStBhxfx.png

再從Transition去新增File

https://ithelp.ithome.com.tw/upload/images/20220202/20119035XQlHvlcSKv.png

https://ithelp.ithome.com.tw/upload/images/20220202/20119035Q4uackymcV.png

Manager改成Set

https://ithelp.ithome.com.tw/upload/images/20220202/201190354EuTzdtF0r.png

Manager改成Set

https://ithelp.ithome.com.tw/upload/images/20220202/20119035uhu5c6aVfQ.png

https://ithelp.ithome.com.tw/upload/images/20220202/20119035GDaWzE3xR3.png

可以參考官方文件-
https://developer.android.com/reference/android/transition/Transition

https://ithelp.ithome.com.tw/upload/images/20220202/20119035S7efgEOodd.png

再到第一頁的MainActivity.java檔新增

https://ithelp.ithome.com.tw/upload/images/20220202/20119035DTCfjFBS4J.png

package com.huang.mytransition;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityOptionsCompat;

import android.content.Intent;
import android.os.Bundle;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //建立動畫
      Transition explode = TransitionInflater.from(this).inflateTransition(android.R.transition.explode);
      Transition slide = TransitionInflater.from(this).inflateTransition(android.R.transition.slide_bottom);
        Transition fade = TransitionInflater.from(this).inflateTransition(android.R.transition.fade);
        Transition myFade = TransitionInflater.from(this).inflateTransition(android.R.transition.fade);

      //指定執行時間點

        getWindow().setEnterTransition(fade);
        getWindow().setEnterTransition(fade);

    }

    public void onClick(View view) {

        Intent it = new Intent();
        it.setClass(MainActivity.this,Page2.class);
        //startActivity(it);
        startActivity(it,
                ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this).toBundle());
    }



    }

Page2.java檔新增

https://ithelp.ithome.com.tw/upload/images/20220202/201190351RjNGiX3uT.png

package com.huang.mytransition;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityOptionsCompat;

import android.content.Intent;
import android.os.Bundle;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.view.View;

public class Page2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_page2);

        //建立動畫
        Transition explode = TransitionInflater.from(this).inflateTransition(android.R.transition.explode);
        Transition slide = TransitionInflater.from(this).inflateTransition(android.R.transition.slide_bottom);
        Transition fade = TransitionInflater.from(this).inflateTransition(android.R.transition.fade);
        Transition myFade = TransitionInflater.from(this).inflateTransition(android.R.transition.fade);

        //指定執行時間點

        getWindow().setEnterTransition(fade);
        getWindow().setEnterTransition(fade);

    }

    public void onClick(View view) {

        Intent it = new Intent();
        it.setClass(Page2.this, MainActivity.class);
        //startActivity(it);
        startActivity(it,
                ActivityOptionsCompat.makeSceneTransitionAnimation(Page2.this).toBundle());
    }
}

fade.xml檔

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"

    android:duration="500"
    android:fadingMode="fade_in_out"

    tools:ignore="MissingDefaultResource">



</transitionSet>

其實我覺得長的都一樣
/images/emoticon/emoticon02.gif

搜尋時要注意的
1-關鍵字要有github-->例如:gl-transition android github
2-年代

https://ithelp.ithome.com.tw/upload/images/20220202/20119035vGWsX6RF1F.png

https://github.com/lgvalle/Material-Animations

不能整個檔案開,不能~~~要用java和xml貼.因為每個人的版本不同


上一篇
第13天~
下一篇
第15天~Spinner
系列文
就是從無到有寫app31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言